﻿using System;
using System.Windows;
using System.Windows.Data;

namespace OpenLightGroup.Common.Converters
{
    /// <summary>
    /// Returns a Visibility Enum value based on whether the bound value is null. Also excepts the string "Inverse" as a parameter to return Visible if the value is null.
    /// </summary>
    public class NullToVisibilityConverter : IValueConverter
    {

        #region IValueConverter Members
        /// <summary>
        /// Returns a Visibility Enum value based on whether the bound value is null. Also excepts the string "Inverse" as a parameter to return Visible if the value is null.
        /// </summary>
        /// <param name="value">Object to evaluate for null</param>
        /// <param name="targetType">Not used</param>
        /// <param name="parameter">Can be the string "Inverse" to invert the logic.</param>
        /// <param name="culture">Current culture info.</param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null) 
            {
                return (value == null) ? Visibility.Collapsed : Visibility.Visible;
            }
            else if (parameter.ToString().ToLower(culture) == "inverse")
            {
                return (value == null) ? Visibility.Visible : Visibility.Collapsed;
            }
            return Visibility.Collapsed;
        }


        /// <summary>
        /// Not implemented.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

}
